package com.thxr.sso.server.service.impl;

import com.thxr.sso.client.rpc.Result;
import com.thxr.sso.server.mapper.EntryMapper;
import com.thxr.sso.server.pojo.Entry;
import com.thxr.sso.server.service.EntryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service("entryService")
public class EntryServiceImpl implements EntryService {
	@Autowired
	private EntryMapper entryMapper;

	@Override
	public Result findByCode(String code) {
		Example example = new Example(Entry.class);
		example.createCriteria().andEqualTo("code", code);
		List<Entry> entryList = entryMapper.selectByExample(example);

		if (entryList == null || entryList.size() == 0){
			return Result.createError("联系管理员查看项目管理系统--应用中的代号是否已更改");
		}
		Entry entry = entryList.get(0);

		return Result.createSuccess(entry);
	}
}
